#include<bits/stdc++.h>
using namespace std;

#define int long long
#define mp make_pair
#define F first
#define S second

int T, n, m, L, V, r1, r2, d[100010], v[100010], a[100100], p[100010];
vector<pair<int, int> > q;

signed main(){
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> T;
    while(T--){
        cin >> n >> m >> L >> V, q.clear(), r1 = 0, r2 = 0;
        for(int i = 1; i <= n; i++)
            cin >> d[i] >> v[i] >> a[i];
        for(int i = 1; i <= m; i++)
            cin >> p[i];
        for(int i = 1; i <= n; i++){
            if(a[i] < 0 && v[i] < V)
                continue;
            int ind = lower_bound(p + 1, p + m + 1, d[i]) - p;
            if(a[i] == 0){
                if(ind <= m && v[i] > V)
                    r1++, q.push_back(mp(ind, m));
                continue;
            }
            if(a[i] > 0){
                int l = ind, r = m;
                while(l < r){
                    int mid = (l + r) / 2;
                    if(V * V - v[i] * v[i] < a[i] * 2 * (p[mid] - d[i]))
                        r = mid;
                    else
                        l = mid + 1;
                }
                if(V * V - v[i] * v[i] < a[i] * 2 * (p[l] - d[i]))
                    r1++, q.push_back(mp(l, m));
                continue;
            }
            if(V * V - v[i]* v[i] < a[i] * 2 * (p[ind] - d[i])){
                int l = ind, r = m;
                while(l < r){
                    int mid = (l + r) / 2 + 1;
                    if(V * V - v[i]* v[i] < a[i] * 2 * (p[mid] - d[i]))
                        l = mid;
                    else
                        r = mid - 1;
                }
                if(V * V - v[i] * v[i] < a[i] * 2 * (p[l] - d[i]))
                    q.push_back(mp(ind, l)), r1++;
            }
        }
        cout << r1 << ' ';
        int lst = -1;
        sort(q.begin(), q.end());
        for(int i = 0; i < q.size(); ){
            int j = i, mx = 1e18;
            while(j < q.size() && q[j].F <= mx)
                mx = min(mx, q[j].S), j++;
            r2++, i = j;
        }
        cout << m - r2 << endl;
        for(int i = 1; i <= n; i++)
            d[i] = v[i] = a[i] = 0;
        for(int i = 1; i <= m; i++)
            p[i] = 0;
    }
    return 0;
}